/* 
 *   Date       Developer   Description
 *   
 *
 *   Classname:  zzz.test.component.controlbus.Test01
 * 
 *   Date:   2014-3-11
 * 
 *   The source code contained in this listing is proprietary to
 *   HLJ POST YITONG INFO-NET CO.,LTD.
 * 
 *   Unauthorized copying, adaptation, distribution, use, or display
 *   is strictly prohibited.
 *   This software is Copyright 2014 HLJ POST YITONG INFO-NET CO.,LTD.
 */
package com.titan.demo.camel.sample.component.controlbus;

import org.apache.camel.CamelContext;
import org.apache.camel.ConsumerTemplate;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;

import com.titan.demo.camel.utils.CamelUtils;


/**
 *
 *
 * @author Administrator
 *
 */
public class Test01 {

    public static void main(String[] args) {
        CamelContext context = null;
        ProducerTemplate template = null;
        ConsumerTemplate consumer = null;
        try {
            context = new DefaultCamelContext();
            context.addRoutes(new RouteBuilder() {
                public void configure() {
                    from("direct:foo").routeId("foo").to(CamelUtils.log("a")).to("mock:foo");
                }
            });
            
            template = context.createProducerTemplate();
            template.start();
            consumer = context.createConsumerTemplate();
            consumer.start();
            context.start();
            
            String action = "start";  // start stop status
            String xml = template.requestBody("controlbus:route?routeId=foo&action="+action, "Hello World", String.class);
            System.out.println(xml);
            
//            MockEndpoint mock = context.getEndpoint("mock:foo", MockEndpoint.class);
//            mock.expectedMessageCount(1);
//            mock.expectedBodiesReceived("Hello World");
//            template.sendBody("direct:foo", "Hello World");
//            mock.assertIsSatisfied();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            CamelUtils.close(consumer);
            CamelUtils.close(template);
            CamelUtils.close(context);
        }
    }

}

